<?php

function get_opsi_seting($name){
	$query = "SELECT value FROM opsi_seting WHERE name='{$name}' LIMIT 1";
	$res = my_query($query);
	$row = my_fetch_array($res);
	return $row['value'];
}


function form_date_converter($str){
	list( $dd , $mm , $yyyy ) = explode( "-" , $str );
	return $yyyy.'-'.$mm.'-'.$dd;
}
function is_calon($karyawan_id){
	$query = "SELECT karyawan_id FROM karyawan_disable WHERE karyawan_id = {$karyawan_id} ";
	$result = my_query($query);
	if(my_num_rows($result) > 0){
		return true;
	}
	return false;
}
function table_cetak_builder($header , $datas ,  $footer_length , $property_table = false, $footer_content = false  ){

 
	if(! $property_table){
		$property_table = array(
			'style'=>'border-collapse:collapse;margin:2px;',
			'cellpadding'=>'2',
			'cellspacing'=>'0'
		);
	}
	
	if(! is_array($property_table) ){
		return (-1);
	}
	
	$view = '<table cellspacing="4px" class="content_view" ';
	foreach($property_table as $table=>$property){
		$view .= $table.'="'.$property.'" ';
	}
	$view .='>'."\n";

	if(! is_array($header) ){
		return (-2);
	}	 
	$view .='<tr>';
	foreach($header as $field=>$length){
		$view .='<td ';
		foreach($length as $th => $value){
			$view .= $th.'="'.$value.'" ';
		}
		$view .='><b>'.strtoupper($field).'</b></td>';
 	}
	$view .='</tr>'."\n";	
	if( $datas ){
		$view .= $datas."\n";
	}else{
		$view .= '<tr>';
		$view .= '<td colspan="'.$footer_length.'" style="height:34px;text-align:center;border-bottom:2px solid;">No data available</td>';
		$view .= '</tr>'."\n";
	}
	$view .='<tr><th colspan='.  $footer_length .'>'."\n";
	if($footer_content && $datas ){
		$view .= $footer_content;
	}else{
		$view .= '&nbsp;';
	}
	$view .='</th></tr>'."\n";
	$view .='</table>'."\n<br/>";

	return $view;
}


function table_cetak_rows($fields){

	if(! is_array($fields) ){
		return (-1);
	}
	$n = 0; 
	if(count($fields) == 0):
			return false;
	else: 
		$total_rows = count($fields);
		foreach($fields as $key=>$values){
			
			$bgrows = ( ($n%2) == 0 ) ? '#DEDEDE' : '#EFEFEF' ;
			
			$view .= '<tr>';
			foreach( $values as $k => $value){
				if(($total_rows -1 )== $n)
				$view .= '<td style="vertical-align:top;height:24px; border-bottom:2px solid;" class="'.$k .'">'.$value.'</td>';
				else
				$view .= '<td style="vertical-align:top;height:24px;" class="'.$k .'">'.$value.'</td>';
			}
			$view .= '</tr>';
			
			$n++;
		}
	endif;
	return $view;
}

function table_builder($header , $datas ,  $footer_length , $property_table = false, $footer_content = false  ){

 
	if(! $property_table){
		$property_table = array(
			'style'=>'border-collapse:collapse;margin:2px;',
			'cellpadding'=>'2',
			'cellspacing'=>'0'
		);
	}
	
	if(! is_array($property_table) ){
		return (-1);
	}
	
	$view = '<table width="100%" ';
	foreach($property_table as $table=>$property){
		$view .= $table.'="'.$property.'" ';
	}
	$view .='>'."\n";

	if(! is_array($header) ){
		return (-2);
	}	 
	$view .='<tr style="color:#EFEFEF;background-color:#010101;border-top:1px solid #000000;border-bottom:1px solid #000000;">';
	foreach($header as $field=>$length){
		$view .='<th align="left" ';
		foreach($length as $th => $value){
			$view .= $th.'="'.$value.'" ';
		}
		$view .='><b>'.strtoupper($field).'</b></th>';
 	}
	$view .='</tr>'."\n";
	 
	if( $datas ){
		$view .= $datas."\n";
	}else{
		$view .= '<tr bgcolor="#FFFFFF">';
		$view .= '<td colspan="'.$footer_length.'" style="height:32px;text-align:center;font:14px verdana;">No data available</td>';
		$view .= '</tr>'."\n";
	}
	$view .='<tr><th colspan='.  $footer_length .'>'."\n";
	if($footer_content  ){
		$view .= $footer_content;
	}else{
		$view .= '&nbsp;';
	}
	$view .='</th></tr>'."\n";
	$view .='</table>'."\n";

	return $view;
}


function table_rows($fields , $style =false){
	$view = "";
	if(! is_array($fields) ){
		return (-1);
	}
	$n = 0; 
	if(count($fields) == 0):
			return false;
	else:
		foreach($fields as $key=>$values){
			
			$bgrows = ( ($n%2) == 0 ) ? '#FFC9C9' : '#FFDEDE' ;
			
			$view .= '<tr style="font:12px verdana;background-color:'.$bgrows.'"  >';
			foreach( $values as $k => $value){
				$view .= '<td class="cellvalue">'.$value.'</td>';
			}
			$view .= '</tr>';
			
			$n++;
		}
	endif;
	return $view;
}

function table_builder_plain($header , $datas ,  $footer_length , $property_table = false, $footer_content = false  ){

 
	if(! $property_table){
		$property_table = array(
			'style'=>'border-collapse:collapse;margin:2px;',
			'cellpadding'=>'2',
			'cellspacing'=>'0'
		);
	}
	
	if(! is_array($property_table) ){
		return (-1);
	}
	
	$view = '<table width="100%" ';
	foreach($property_table as $table=>$property){
		$view .= $table.'="'.$property.'" ';
	}
	$view .='>'."\n";

	if(! is_array($header) ){
		return (-2);
	}	 
	$view .='<tr  style="background:#CDCDCD;height:30px;font:12px verdana;font-weight:bold;text-align:left;color:#000;" >';
	foreach($header as $field=>$length){
		$view .='<th valign="middle" ';
		foreach($length as $th => $value){
			$view .= $th.'="'.$value.'" ';
		}
		$view .='><b>'.strtoupper($field).'</b></th>';
 	}
	$view .='</tr>'."\n";
	 
	if( $datas ){
		$view .= $datas."\n";
	}else{
		$view .= '<tr bgcolor="#FFFFFF">';
		$view .= '<td colspan="'.$footer_length.'" style="height:34px;text-align:center;font-size:14px;">No data available</td>';
		$view .= '</tr>'."\n";
	} 
	
	if( $footer_content ){
		$view .= '<tr bgcolor="#CDCDCD">';
		$view .= '<td colspan="'.$footer_length.'" style="height:20px;text-align:right;font-size:14px;">'.$footer_content.'</td>';
		$view .= '</tr>'."\n";	
	}
	$view .='</table>'."\n";

	return $view;
}


function table_rows_plain(	$fields ){
	$view = "";
	if(! is_array($fields) ){
		return (-1);
	}
	$n = 0; 
	if(count($fields) == 0):
			return false;
	else:
		foreach($fields as $key=>$values){ 
			$view .= '<tr style="border-bottom:1px solid #CDCDCD;border-top:1px solid #CDCDCD;font:12px verdana;" onMouseOver="this.style.backgroundColor=\'#E1EAFE\'"; onMouseOut="this.style.backgroundColor=\'transparent\'"style="border-top:1px solid #000;border-bottom:1px solid #000;">';
			foreach( $values as $k => $value){
				$view .= '<td>'.$value.'</td>';
			}
			$view .= '</tr>';
			
			$n++;
		}
	endif;
	return $view;
}

function position_text_align( $content , $position = 'left' ){
	return '<div style="text-align:'.$position.'">'.$content.'</div>';
}


function symbol_breadcumb(){
	return button_icon( 'b_nextpage.png' ,array() );
}
 
function button_icon( $icon , $urlproperty = false , $buttonproperty=false ){
	$view ='';
	if($urlproperty){
		if(! is_array($urlproperty) ) return false;
			if($urlproperty)
				$view .='<a ';
			
			foreach($urlproperty as $key=>$value){
				$view .= $key . '="' . $value.'" ';
			}
				
			if($urlproperty)
				$view .='>';
	}	
	
		$view .='<img src="'._PREFIXDOMAIN_.'/templates/icons/'.$icon.'" border="0" ';
		if($buttonproperty){
			if(is_array($buttonproperty)){
				foreach($buttonproperty as $bkey=>$bvalue){
					$view .= $bkey . '="' . $bvalue.'" ';
				}
			}
		}
		$view .='/>';
	if($urlproperty) $view .='</a>';

	return $view;
}


function tab_page($tab_options , $contents ){

	if(! is_array($tab_options)) return false;
	my_set_code_css(
	'h1 {font-size: 3em; margin: 20px 0;}
.container {width: 900px; height:350px; margin: 10px auto;}
ul.tabs {
	margin: 0;
	padding: 0;
	float: left;
	list-style: none;
	height: 25px;
	border-bottom: 1px solid #999;
	border-left: 1px solid #999;
	width: 100%;
}
ul.tabs li {
	float: left;
	margin: 0;
	padding: 0;
	height: 24px;
	line-height: 26px;
	border: 1px solid #999;
	border-left: none;
	margin-bottom: -1px;
	background: #D40300;
	overflow: hidden;
	position: relative;
}
ul.tabs li a {
	text-decoration: none;
	color: #fff;
	display: block;
	font: 11px Georgia;
	text-transform:uppercase; 
	padding: 5px 20px;
	border: 1px solid #fff;
	outline: none;
	height:22px;

}
ul.tabs li a:hover {
	background: #e0e0e0;
	color: #000;
}	
html ul.tabs li.active, html ul.tabs li.active a:hover  {
	background: #fff;
	border-bottom: 1px solid #fff;
	
}
html ul.tabs li.active a{
font: 11px Georgia #000; 
color: #000;
}

.tab_container {
	border: 1px solid #999;
	border-top: none;
	clear: both;
	float: left; 
	width: 100%;
	background: #fff;
	-moz-border-radius-bottomright: 5px;
	-khtml-border-radius-bottomright: 5px;
	-webkit-border-bottom-right-radius: 5px;
	-moz-border-radius-bottomleft: 5px;
	-khtml-border-radius-bottomleft: 5px;
	-webkit-border-bottom-left-radius: 5px;
}
.tab_content {
	padding: 20px;
	font-size: 1.2em;
}
.tab_content h2 {
	font-weight: normal;
	padding-bottom: 10px;
	border-bottom: 1px dashed #ddd;
	font-size: 1.8em;
}
.tab_content h3 a{
	color: #254588;
} 
');

$sestab = isset($_SESSION['tab_page']) ? '"'. $_SESSION['tab_page'] .'"': '"ul.tabs li:first"';
$sestabcon = isset($_SESSION['tab_page']) ? '"'. $_SESSION['tab_page'] .'"': '".tab_content:first"';
	my_set_code_js('
	$(document).ready(function() {

		//Default Action
		$(".tab_content").hide(); //Hide all content
		//$("ul.tabs li#tab3").addClass("active").show(); //Activate first tab
		//$(".tab_content:first").show(); //Show first tab content
		$('.$sestab.').addClass("active").show(); //Activate first tab
		$('.$sestabcon.').show(); //Show first tab content
		
		//On Click Event
		$("ul.tabs li").click(function() {
			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content
			var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active content
			return false;
		});

	}); 
	');
	
	$view = '<div class="container">
<ul class="tabs">';
		foreach($tab_options as $label=>$ref){
        $view .='<li><a href="#'. $ref .'">'. $label .'</a></li> '; 
		}
    $view .= '</ul>'."\n";
	
	$view .= '<div class="tab_container">'."\n";
	foreach($contents as $tabref=>$content){
		$view .= '<div id="'.$tabref.'" class="tab_content">'; 
		$view .= $content;
		$view .='</div>'."\n";
	}
	$view .= '</div></div>'."\n";
	
	unset($_SESSION['tab_page']);
	return $view;
}

function iframe_page( $page , $height ){
	$view .= '<IFRAME src="'.$page.'" MARGINWIDTH="0"  MARGINHEIGHT="0" HSPACE="0" VSPACE="0" FRAMEBORDER="0" SCROLLING=AUTO WIDTH="840" HEIGHT="'.$height.'">test</IFRAME> ';
	return $view;
}

function additional_menu_on_list( $tombols , $text =false ,$property_table = false){
	if(! $property_table){
		$property_table = array(
			'style'=>'border-collapse:collapse;margin:2px;',
			'cellpadding'=>'2',
			'cellspacing'=>'0'
		);
	}
	
	if(! is_array($property_table) ){
		return (-1);
	}
	
	$view = '<table width="100%" ';
	foreach($property_table as $table=>$property){
		$view .= $table.'="'.$property.'" ';
	}
	$view .='>'."\n";
	$view .= '<tr><td align="left" width="40%" valign="bottom">';
	if($text){
		$view .= $text;
	}else{
		$view .='&nbsp;';
	}
	$view .= '</td><td align="right" width="60%" valign="bottom">';
		foreach($tombols as $label=>$subdatas){
			$view .= '<input type="button" class="main_button" value= "'.$label.'" ';
			if(! is_array($subdatas))return false;
			foreach($subdatas as $ds=>$pr){
				$view .= $ds .'="'. $pr .'" ';
			}			
			$view .='/> ';
		}
	$view .= '</td></tr>'."\n";
	$view .= '</table>'."\n";
	return $view;
}

function button_menu_on_top($datas,$left=false){

	$view ='<div id="menu-top" align="right">';
	if($left)$view .='<div style="float:left;width:350px;text-align:left;">'.$left.'</div>';
	foreach( $datas as $label=>$subdatas){
		$view .= '<div id="eachmenu"><a href="javscript:;" ';
			if(! is_array($subdatas))return false;
			foreach($subdatas as $ds=>$pr){
				$view .= $ds .'="'. $pr .'" ';
			}
		$view .= '>'.strtoupper($label).'</a></div>';
	}
	$view .='<div style="clear:both"></div></div>';
	return $view;
}
 
function message_plainpage($message){
	generate_my_web("<center><b>{$message}</b></center>","","plain.php");
	exit;
}


function detail_header_view( $line_color="#000"  ){ 
	$viewed = ' 	
	<table width="98%"   style="border-collapse:collapse;border-color:'.$line_color.'" cellspacing="0" cellpadding="2">
	   ';
	
	return $viewed;
}

function detail_rows_view($label , $value ,$merge = false , $a="30%" , $b="68%"){
	if($merge)
	$view  ='
	<tr  style="border-top: 1px solid;border-bottom: 1px solid #CDCDCD;border-top: 1px solid #CDCDCD; ">
		<td colspan="2" width="100%"   valign="top" style="padding:4px">'. ucfirst($label). '</span></td> 
	</tr>';

	else
	$view  ='
	<tr  style="border-top: 1px solid;border-bottom: 1px solid #CDCDCD;border-top: 1px solid #CDCDCD; ">
		<td width="'.$a.'"  valign="top" style="padding:4px;font:12px verdana"><b>'. ucfirst($label) .'</b></td>
		<td width="'.$b.'"style="padding:4px;font:12px verdana">'.$value . ' </td>
	</tr>';
	return $view;
}
function detail_footer_view(){
	 $viewed = '
	  </table> ';
	return $viewed;
}


function detail_rows_cetak($datas , $paper = 'L'){
	if(! is_array($datas))return false;
	$view ='<table style="width: 100%;" align="center">';
	foreach($datas as $label=>$value){
		$view .='<tr> 
			<td style="vertical-align: top; padding: 2px; width: '.($paper == 'L' ? '25%' : '35%').'; text-align: left;">
			<b>';
		$view .=$label;	
		$view .='</b>	</td>';
		$view .='<td style="vertical-align: top; padding: 2px; width: '.($paper == 'L' ? '75%' : '65%').'; text-align: left;"> 
				';
		$view .=$value;		
		$view .='	</td>
		</tr>';
	}
	$view .='</table>';
	return $view;
}

function dropdown_multi_rows_extends_dua( $parent , $child , $file_combo , $opsi_pilihan   ){

	my_set_file_js(array( 
		'components/system/jquery/combomulti/jquery.chainedSelects.js'
	));  
	my_set_code_js(' 
	$(function()
	{  
		$(\'#'.$parent['id'].'\').chainSelect(\'#'.$child['id'].'\',\''.$file_combo.'\',
		{ 
			before:function (target) 
			{ 
				$("#'.$child['id'].'loading").css("display","block");  
				$("#'.$child['id'].'default").css("display","none"); 
				$(target).css("display","none");
			},
			after:function (target) 
			{ 
				$("#'.$child['id'].'loading").css("display","none");  
				$("#'.$child['id'].'default").css("display","none"); 
				$(target).css("display","inline");
			},
			parameters : {\'tingkat\' : $("#tingkat").val() }
		}); 
		settings.parameters.tingkat =  $("#tingkat").val();
	});
	' );
	my_set_code_css('
	#'.$child['id'].'default
		{  
			background:#ff0000;
			color:#fff;
			font-size:14px;
			font-familly:Arial;
			padding:2px; 
			display:block;
			float:left;
		} 
	
	#'.$child['id'].'loading
		{  
			background:#ff0000;
			color:#fff;
			font-size:14px;
			font-familly:Arial;
			padding:2px; 
			display:none;
			float:left;
		} 
	'); 

	
	if($opsi_pilihan ){
	}else{
		$opsi_pilihan='<option>[- Pilih atas dulu -]</option>' ;
	}	
	$vi = '
	<span id="'.$child['id'].'loading" style="float:left;">Loading ...</span>
	<select name="'.$child['name'].'" id="'.$child['id'].'">
	'.$opsi_pilihan.'
	</select>' ;
	return $vi;	
}

function dropdown_multi_rows_extends( $parent , $child , $parent_datas , $file_combo ,$runsc = true ){
	my_set_file_js(array( 
		'components/system/jquery/combomulti/jquery.chainedSelects.js'
	));  
	my_set_code_js(' 
	$(function()
	{ 
		$(\'#'.$parent['id'].'\').chainSelect(\'#'.$child['id'].'\',\''.$file_combo.'\',
		{ 
			before:function (target) 
			{ 
				$("#'.$child['id'].'loading").css("display","block");  
				$("#'.$child['id'].'default").css("display","none"); 
				$(target).css("display","none");
			},
			after:function (target) 
			{ 
				$("#'.$child['id'].'loading").css("display","none");  
				$("#'.$child['id'].'default").css("display","none"); 
				$(target).css("display","inline");
			}
		}); 
	});
	' );
	my_set_code_css('
	#'.$child['id'].'default
		{  
			background:#ff0000;
			color:#fff;
			font-size:14px;
			font-familly:Arial;
			padding:2px; 
			display:block;
			float:left;
		} 
	
	#'.$child['id'].'loading
		{  
			background:#ff0000;
			color:#fff;
			font-size:14px;
			font-familly:Arial;
			padding:2px; 
			display:none;
			float:left;
		} 
	');
	if(!$runsc)return true;
	
	$vi = array();
	if(  is_array($parent_datas)    )
	$vi['parent'] = form_dropdown($parent , $parent_datas );
	
	if($child)
	$vi['child'] = '<span id="'.$child['id'].'loading" style="float:left;">Loading ...</span><select name="'.$child['name'].'" id="'.$child['id'].'" style="display:none;"></select><span id="'.$child['id'].'default">[- Pilih atas dulu -]</span>';
	return $vi;	
}

function check_jabatan_by_name($name){
	$name = strtoupper($name);
	$query = "SELECT  jabatan_id FROM jabatan 
	WHERE UPPER(nama_jabatan) ='{$name}' ";
	$result = my_query($query);
	if(my_num_rows($result) > 0 ){
		$row = my_fetch_array($result);
		return $row['jabatan_id'];
	}
	
	return 0;
}

function check_jabatan_by_no_org($no_org){
	$npos=strpos($no_org,"/");
	$no_org=rtrim(substr($no_org,0,$npos));
	$no_org = strtoupper(trim($no_org));
	if( (int)$no_org > 0 ){
		$query = "SELECT * FROM  jabatan a
			INNER JOIN sk_jabatan b ON b.sk_id=a.sk_id
			WHERE b.active='Y' 
			AND a.nomor_posisi ='{$no_org}' "; 
	}else{
		$query = "SELECT * FROM  jabatan a
			INNER JOIN sk_jabatan b ON b.sk_id=a.sk_id
			WHERE b.active='Y' 
			AND a.nama_jabatan ='{$no_org}' "; 
	}
	$result = my_query($query);
	if(my_num_rows($result) > 0 ){
		$row = my_fetch_array($result);
		return $row['jabatan_id'];
	}
	
	return 0;
}
function set_text_as_number($angka){
	$text = explode( ",",$angka);
	return (int) str_replace("." ,"",$text[0]);
}

function rupiah_format($number){
	return  number_format($number, 2, ',', '.') ;
}

function set_text_as_rupiah($angka){ //8 Juni 2011 by anto
	$text = str_replace("." ,"",$angka);
	$text = explode( ",",$text);
	if( (int) $text[1] > 0){
		return $text[0].'.'.$text[1];
	}
	return $text[0] ;
}

function rp_format($number){
	return  number_format($number, 0, ',', '.') ;
}

function check_karyawan_by_name($name){
	$name = strtoupper(trim($name));
	$query = "SELECT a.karyawan_id FROM karyawan a
	INNER JOIN biodata b ON a.biodata_id = b.biodata_id
	WHERE UPPER(b.nama) ='{$name}' ";
	 
	$result = my_query($query);
	if(my_num_rows($result) > 0 ){
		$row = my_fetch_array($result);
		return $row['karyawan_id'];
	}
	
	return 0;
}

function check_karyawan_by_nik_nama($nik_nama){
	$nik=$nik_nama;
	$npos=strpos($nik,"/");
	$nik=rtrim(substr($nik,0,$npos));
	$nik = strtoupper(trim($nik));
	$query = "SELECT karyawan_id FROM karyawan 
	WHERE UPPER(nik) ='{$nik}' ORDER BY karyawan_id DESC LIMIT 1";
	 
	$result = my_query($query);
	if(my_num_rows($result) > 0 ){
		$row = my_fetch_array($result);
		return $row['karyawan_id'];
	}
	
	return 0;
}

function check_karyawan_by_nik($nik_nama){
	$nik=$nik_nama; 
	$nik = strtoupper(trim($nik));
	$query = "SELECT karyawan_id FROM karyawan 
	WHERE UPPER(nik) ='{$nik}' ORDER BY karyawan_id DESC LIMIT 1";
	 
	$result = my_query($query);
	if(my_num_rows($result) > 0 ){
		$row = my_fetch_array($result);
		return $row['karyawan_id'];
	}
	
	return 0;
}

function remove_data_load_js( $url ){
	
	my_set_code_js('
function deleteRecordFromApplication(id){
	var t = confirm(\'Yakin akan menghapus data ini?\');
	if(t){
		location.href=\''.$url.'\'+ id;
	}
	return false;
}	
	');
}

function remove_data_button($id , $f = true){
	if($f){
		$deleteproperty = array(
				'href'=>'javascript:; ',
				'onclick'=>'javascript:deleteRecordFromApplication('.$id.');',
				'title'=>'Delete'
		);
		return button_icon( 'b_drop.png' , $deleteproperty  );
	}else{
		$deleteproperty = array(
				'href'=>'javascript:; ',
				'onclick'=>'javascript:alert(\'Data tidak dapat didelete\');',
				'title'=>'Delete off'
		);
		return button_icon( 'b_drop_off.png' , $deleteproperty  );
	}
}

function remove_data_from_application( $table_name , $field_key , $data_id ){

	return my_delete_record( $table_name , $field_key , $data_id );
}


function is_set_to_komponen($karyawan_id  , $komponen_gaji_id ){
	$karyawan = loaddata_karyawan($karyawan_id);
	$komponen = my_get_data_by_id( 'pr_komponen_gaji' , 'komponen_gaji_id' , $komponen_gaji_id );
	
	$karyawan_status_id = $karyawan['status_kekaryawan_id'];
	$st = array(
		'1'=>'Organik',
		'2'=>'Kontrak',
		'3'=>'Perbantuan',
	);
	$ll = strtolower($st[$karyawan_status_id]);
	if($komponen[$ll] == 'yes' ){
		return true;
	}
	return false;
}


function get_next_periode_id(){
	$query = " SELECT  DATE_ADD(tanggal  , INTERVAL 1 MONTH) AS stanggal FROM pr_periode ORDER BY periode_id DESC LIMIT 1";
	$result = my_query($query);
	$data = my_fetch_array($result);
	return  $data['stanggal'];
} 

function get_periode_absen(){
	$query = " SELECT  periode_id FROM pr_periode WHERE absen='Active' LIMIT 1";
	$result = my_query($query);
	$data = my_fetch_array($result);
	return  (int) $data['periode_id'];
} 

function get_last_periode_id($periode_id){
	$periode = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$month = date('m',strtotime($periode['tanggal']));
	$year = date('Y',strtotime($periode['tanggal']));
	if($month==1){
		$month=12;
		$year--;
	}else{
		$month--;
	}
	$tanggal=$year.'-'.sprintf( '%02d',$month) .'-01';
	$periods = my_get_data_by_id('pr_periode','tanggal',"'".$tanggal."'");
	if($periods){
		return $periods['periode_id'];
	}else{
		return 0;
	}
}	

function get_periode_gaji(){
	$query = " SELECT  periode_id FROM pr_periode WHERE gaji='Active' LIMIT 1";
	$result = my_query($query);
	$data = my_fetch_array($result);
	return  $data['periode_id'];
}

	
function get_data_penyesuaian($komponen_gaji_id , $karyawan_id){
	$query = "
			SELECT nominal FROM pr_penyesuaian  
			WHERE  karyawan_id = {$karyawan_id } AND komponen_gaji_id ={$komponen_gaji_id}
		";	 
		$dres = my_query($query);
		$drow = my_fetch_array($dres);
		return $drow['nominal'];
}


function getlamakerja($date , $start) {
	list(	$bYear, $bMonth, $bDay 	) = explode("-",$date);
	list(	$cYear, $cMonth, $cDay 	) = explode("-",$date); 

	if(($cMonth >= $bMonth && $cDay >= $bDay) || ($cMonth > $bMonth)) {
		return ($cYear - $bYear);
	} else {
		return ($cYear - $bYear - 1);
	}
}

function getshifttersedia($jabatan_id ){
	
	$query = "SELECT count(*) AS total_data FROM kekaryawanan
	WHERE jabatan_id = {$jabatan_id} "; 
	$result = my_query($query);
	$row = my_fetch_array($result);
	$avai_data=$row['total_data'] ;
	$query = "SELECT jabatan_id FROM jabatan_terkait_link  
	WHERE parent_jabatan_id  =".$jabatan_id ;
	$result = my_query($query);
	while($ey = my_fetch_array($result)){
		$query = "SELECT count(*) AS total_data FROM kekaryawanan
			WHERE jabatan_id = {$ey['jabatan_id']} ";	
			$result = my_query($query);
			$row = my_fetch_array($result);
			$avai_data+=$row['total_data'] ;
	}		
	return $avai_data ;
}

function getjumlahkandidat($jabatan_id ){
	$jumlahkandidat=0;
	$query = "SELECT jabatan_id FROM jalur_karir_rotasi
		WHERE new_jabatan_id = {$jabatan_id} ";
	$result = my_query($query);
	while($ey = my_fetch_array($result) ){
		$query = "SELECT count(*) AS total_data FROM kekaryawanan 
		WHERE jabatan_id = {$ey['jabatan_id']} ";
		$dres = my_query($query);
		$row = my_fetch_array($dres);
		$jumlahkandidat+=$row['total_data']; 		
	}
	return $jumlahkandidat; 
}

 function returnDate($num, $tipe){
	$str;
	switch($tipe){
		case "month":
			$month_name = array("", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember");
			$str = $month_name[floor($num)];
			break;
		case "day":
			$day_name = array("", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu", "Minggu");
			$str = $day_name[floor($num)];
			break;
	}
   
	return $str;
	
/*
		contoh pemakaian : returnDate(date("N"), "day") . ", " . date("j") . " " . returnDate(date("n"), "month") . " " . date("Y")
*/		
}


function showMenuLable($menu_id){
	$query = "SELECT * FROM daftar_menu a INNER JOIN daftar_menu_akses b
	ON a.menu_id=b.menu_id WHERE b.user_id = {$_SESSION['user_id']} 
	AND a.menu_id = {$menu_id}";
	$result = my_query($query);
	if(my_num_rows($result) == 0){
		$menu = my_get_data_by_id('daftar_menu','menu_id',$menu_id);
		return '<a href="javascript:void;" onclick="alert(\'Akses di tolak !\');" title="'.$menu['label'].'">'.$menu['label'].'</a>';
	}
	if( $row = my_fetch_array($result) ){
		return '<a href="'.$row['link'].'" title="'.$row['label'].'">'.$row['label'].'</a>';
	} 
}

function accessPage($menu_id){
	$query = "SELECT * FROM daftar_menu a INNER JOIN daftar_menu_akses b
	ON a.menu_id=b.menu_id WHERE b.user_id = {$_SESSION['user_id']} 
	AND a.menu_id = {$menu_id}";
	$result = my_query($query);
	if(my_num_rows($result) == 0){
		fatal_error('Tidak ada hak akses');
	}
}

function karyawan_header_detail($karyawans , $pajak =false, $newline = false){
my_set_code_js('  
function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
}   
function checkName(name){ 
	$.get("check_karyawan_nik.php", { nik: name  },
	   function(data){
		 if(data ==  \'0\' ){
			alert(\'NIK  \'+ name+\' tidak ditemukan\nHarap diperiksa kembali\');
			$(\'#nik_karyawan\').val(\''.$karyawans['nik'].'\');
			return false;
		 } 
	   });
}');
	if(! is_array($karyawans))return false; 
	$photo = my_get_data_by_id('photo','biodata_id',$karyawans['biodata_id']);
	$view ='<table width="98%" cellspacing="0" cellpadding="4"><tr><td width="15%" align="center" style="background:#CDCDCD" valign="top">';
	if(file_exists($photo['upload_path']))
		$view .= '<img src="'.$photo['upload_path'].'" width="120px" height="160px"/><br/>';
	else
		$view .= '<img src="files/upload/sample_thumb.jpg" width="120px" height="160px"/><br/>';
		
	$view_admin  = '<a href="index.php?com=karyawan&task=ganti_photo&id='.$karyawans['karyawan_id'].'" rel="facebox" style="font:10px verdana;">[Ganti photo]</a>	';
	if(is_admin() && $_GET['com'] =='karyawan')$view .=$view_admin;
	$view .='</td><td width="85%" align="left" valign="bottom">';
	$view .= '<form method="GET">'.form_header_no_post( "detail pegawai" , "cp"  );
	
	$jabatan = loaddata_jabatan($karyawans['jabatan_id']); 
	 
	$form = ' 
	<input type="hidden" name="com" value="check_nik"/> 
	<input onkeypress="return handleEnter(this, event)" type="text" id="nik_karyawan" name="nik_karyawan" value="'.$karyawans['nik'].'" onchange="javascript:checkName(this.value)" />
	<input type="submit" value="GO"/>
	 ';


	$nextproperty = array(
						'href'=>'index.php?com=next_prev_karyawan&pr=next&nik_karyawan='.$karyawans['nik'],
						'title'=>'Next',
						'style'=>'border:1px solid;',
				);
	$next_button = button_icon( 'b_lastpage.png' , $nextproperty  );
	$prevproperty = array(
						'href'=>'index.php?com=next_prev_karyawan&pr=prev&nik_karyawan='.$karyawans['nik'],
						'title'=>'Prev',
						'style'=>'border:1px solid;',
				);
	$pos_biaya = my_get_data_by_id('pos_biaya','pos_biaya_id' , (int) $jabatan['pos_biaya_id']); 
	$prev_button = button_icon( 'b_firstpage.png' , $prevproperty  ); 
	$view .= form_field_display( '<span class="label_form">   '.$prev_button.'  &nbsp; '. $form.'  &nbsp; '.$next_button .' </span>&nbsp; &nbsp;  &nbsp; &nbsp;   <b>Status :</b>  ' . ucfirst(str_replace('Karyawan ','',$karyawans['status_karyawan'] ))  , "<b>Nomor induk</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.date('d M Y',strtotime($karyawans['tmb'] )  ) .'</span>'  , "<b>Masuk perusahaan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($jabatan['organisasi_direktorat'] ) .' <b>/</b> '.$jabatan['organisasi_sub_direktorat'] .'</span>', "<b>Direktorat / Subdir</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.ucfirst($jabatan['organisasi_departemen'] ) .' <b>/</b> '.$jabatan['organisasi_bidang'] .'</span>'  , "<b>Departemen / Bidang</b>"    );
	$view .= form_field_display( '<span class="label_form">'.ucfirst($jabatan['nomor_posisi'] ) .' <b>/</b> '.$jabatan['nama_jabatan'] .'</span>' . tombol_facebox_ganti_jabatan($karyawans['karyawan_id'] , $karyawans['jabatan_id'] ,true) , "<b>No. Posisi / Jabatan</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$karyawans['golongan_jabatan'] .'/'.$karyawans['grade_id'].'</span>'  .'&nbsp; &nbsp;  &nbsp; &nbsp;  <b>Premi kekaryawan :</b>  '. '<span class="label_form">'.$karyawans['premi_kesehatan'].'</span>' , "<b>Golongan / Grade</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$pos_biaya['code'] .' '.$pos_biaya['label'].'</span>'   , "<b>Cost center</b>"    ); 
	$view .= form_field_display( '<span class="label_form">'.$karyawans['nama_gelar'].'</span>'   , "<b>Nama karyawan</b>"    ); 

	$view .= form_field_display( '<span class="label_form">'.ucfirst($karyawans['kelamin'] ) .'</span>' .'&nbsp; &nbsp;  &nbsp; &nbsp;  <b>Gol. Darah :</b>  '. '<span class="label_form">'.$karyawans['gol_da'].'</span>' , "<b>Jenis kelamin</b>"    ); 
	if($pajak){
		$view .= form_field_display( '<span class="label_form">'.ucfirst($karyawans['tempat_lahir'] ) .', '.   date('d M Y',strtotime($karyawans['tanggal_lahir'].' 00:00:01')).'</span> &nbsp;  &nbsp; &nbsp; <b>PTKP :</b>  '.$karyawans['ptkp_status'].'/'.$karyawans['ptkp_tanggung'], "<b>Tempat, tanggal lahir</b>"    ); 
	}else{	
		$view .= form_field_display( '<span class="label_form">'.ucfirst($karyawans['tempat_lahir'] ) .', '.   date('d M Y',strtotime($karyawans['tanggal_lahir'].' 00:00:01')).'</span> &nbsp;  &nbsp; &nbsp; <b>Status Perkawinan :</b>  '.$karyawans['marital'] , "<b>Tempat, tanggal lahir</b>"    ); 
	}	
	if($newline){
		if(! is_array($newline))return false;
		foreach($newline as $key=>$line){
			$view .= form_field_display( '<span class="label_form">'. $line     , "<b>{$key}</b>"    ); 		
		}
	}
	
	$view .= form_footer( ); 
	$view .= '</td></tr></table>';
	return $view;
}

function mod($nilai , $var){
	return (($nilai % $var)==0);
}

function tombol_facebox_ganti_jabatan($karyawan_id , $jabatan_id , $viewstatus = false ){

	if($_GET['com'] <> 'jadwal_wk_karyawan')return false;
	$editproperty = array(
					'href'=>'index.php?com=update_jabatan&karyawan_id='.$karyawan_id.'&jabatan_id='.$jabatan_id,
					'rel'=>'facebox',
					'title'=>'Edit'
			);
	$edit_button = button_icon( 'b_edit.png' , $editproperty  );
	$view = '';
	$view .= $edit_button;//' &nbsp; <font size="1"><a href="" rel="facebox"><img src</a></font>';
	return ($viewstatus) ? ' '.$view : '';
}

function form_header_no_post( $label_name , $form_name  ){
 
	$viewed = '
	 	<table width="100%"   style="border-collapse:collapse;border-color:white" cellspacing="0" cellpadding="2">
	   ';
	
	return $viewed;
}

function get_status_shift_absen($karyawan_id , $date){
	if(strlen($karyawan_id) > 6){
		$karyawan_id =check_karyawan_by_nik($karyawan_id);
		if(! $karyawan_id) return false;
	}
	
	$periode_id = get_periode_absen();
	$bln = my_get_data_by_id(	'pr_periode' , 'periode_id' , $periode_id	);
	list($yyyy,$mm,$dd) = explode("-" , $date);
	if( $mm.'-'.$yyyy == date('m-Y' , strtotime($bln['tanggal']))){
		$query = "SELECT * FROM a_realisasi a
		INNER JOIN a_status_absen b ON a.status_absen_id = b.status_absen_id
		WHERE a.karyawan_id = {$karyawan_id} 
		AND field_tgl ='tgl_{$dd}' ";
	}else{
		$query = "SELECT * FROM a_realisasi a
		INNER JOIN a_status_absen b ON a.status_absen_id = b.status_absen_id
		WHERE a.karyawan_id = {$karyawan_id} 
		AND field_tgl ='tgl_{$dd}' AND periode_id = {$periode_id}";
	}
	$result = my_query($query);
	if($row = my_fetch_array($result)){
		return $row;
	}
	return false;
}

function get_status_absen($karyawan_id , $date ){
	$status=array();
	
	if(strlen($karyawan_id) > 6){
		$karyawan_id =check_karyawan_by_nik($karyawan_id);
		if(! $karyawan_id) return false;
	}
	//cuti
	$query="SELECT b.initial_cuti FROM surat_cuti a 
		INNER JOIN a_status_absen b ON a.kelompok_cuti_id = b.status_absen_id 
		WHERE a.tanggal_mulai <='{$date}' 
		AND a.tanggal_selesai >='{$date}' 
		AND a.karyawan_id ={$karyawan_id}";	
	$result = my_query($query);
	if( my_num_rows($result) > 0 ){
		$status[]='Cuti';
	}
	
	//lembur
	$query="SELECT * FROM a_spl 
		WHERE tanggal  ='{$date}' 
		AND karyawan_id ={$karyawan_id}
	";
	/* jamnya nanti */
	$result = my_query($query);
	if( my_num_rows($result) > 0 ){
		$status[] ='Lembur';
	}	

	//spd
	$query="SELECT * FROM spd
		WHERE '".$date."' BETWEEN tanggal_mulai AND tanggal_selesai 
		AND tipe_karyawan='Karyawan' 
		AND karyawan_id ={$karyawan_id}
	";
	$result = my_query($query);
	if( my_num_rows($result) > 0 ){
		$status[]='SPD';
	}	 
	
	//woc *add 8 Juni 2011 by anto
	$query="SELECT * FROM work_on_call_detail a 
		INNER JOIN work_on_call b ON a.work_on_call_id = b.work_on_call_id 
		WHERE b.tanggal <='{$date}' 
		AND b.tanggal >='{$date}' 
		AND a.karyawan_id ={$karyawan_id}";	
	$result = my_query($query);
	if( my_num_rows($result) > 0 ){
		$status[]='WOC';
	}
	
	//ijin
	$query="SELECT * FROM a_surat_ijin
		WHERE tanggal ='{$date}' 
		AND karyawan_id ={$karyawan_id}";	
	$result = my_query($query);
	if( my_num_rows($result) > 0 ){
		$status[]='IJIN';
	}
	
	//tukar dinas
	$query="SELECT * FROM a_tukar_shift
		WHERE tanggal ='{$date}' 
		AND (karyawan_id ={$karyawan_id} 
		OR tukar_karyawan_id={$karyawan_id}) ";	
	$result = my_query($query);
	if( my_num_rows($result) > 0 ){
		$status[]='TUKAR';
	}
	
	return $status;
}


function is_sabtu_minggu($date){
	$hari = date( "D", strtotime($date));
	if($hari == "Sun"){
		return true;
	}
	
	if($hari == "Sat"){
		return true;
	}
	return false;
}

function time_add($a,$b){ 
	if(count(explode(":",$a)) <  3)$a = $a.':00';
	if(count(explode(":",$b)) <  3)$b = $b.':00';
	
	$sum = strtotime($a) + strtotime($b); 
 	return gmdate('H:i:s',$sum); 
}

function time_min($a,$b){
	if(count(explode(":",$a)) <  3)$a = $a.':00';
	if(count(explode(":",$b)) <  3)$b = $b.':00';
	
	$sum = strtotime($a) - strtotime($b);
	return  gmdate('H:i:s',$sum);
}
 
 function get_nipar_by_karyawan_id($karyawan_id){ //8 Juni 2011 by anto
	$nipar=0 ;
	$query = "SELECT jabatan_id, golongan_jabatan_id FROM kekaryawanan WHERE karyawan_id = {$karyawan_id}"; 
	$result = my_query($query );
	$karyawans = my_fetch_array($result);
	$golongan_jabatan_id = isset($karyawans['golongan_jabatan_id'] ) ? $karyawans['golongan_jabatan_id'] : 0  ;
	$jabatan_id = isset($karyawans['jabatan_id'] ) ? $karyawans['jabatan_id'] : 0  ;

	$nipars=my_get_data_by_id('nipar','golongan_jabatan_id',$golongan_jabatan_id );
	$jabatan=my_get_data_by_id('jabatan','jabatan_id',$jabatan_id );
	if($jabatan['sumber_pendukung']=='Sumber'){
		$nipar=$nipars['sumber'] ;
	}elseif($jabatan['sumber_pendukung']=='Pendukung'){	
		$nipar=$nipars['pendukung'] ;
	}
	return $nipar;
}

function get_karyawan_schedule($karyawan_id, $tanggal){ 

	$periode_id=get_periode_id_by_tanggal($tanggal);
	$periode_absen=get_periode_absen() ;
	$jadwal_kerja_kelompok_id =0;
	list($yyyy,$mm,$dd) = explode("-" , $tanggal);
	if($periode_id <= $periode_absen ){
		if( $periode_id==$periode_absen ){
			$query = "SELECT * FROM a_realisasi 
				WHERE karyawan_id = {$karyawan_id} 
					AND field_tgl='tgl_{$dd}' 
					ORDER BY realisasi_id 
					DESC LIMIT 1";
		}else{ 
			$query = "SELECT * FROM a_realisasi_log 
				WHERE karyawan_id = {$karyawan_id} 
					AND	periode_id=".$periode_id." 
					AND field_tgl='tgl_{$dd}' 
					ORDER BY realisasi_id 
					DESC LIMIT 1";
		}
		
		$result = my_query($query);
		if( my_num_rows($result) > 0 ){
			$a_reals = my_fetch_array($result);
			$jadwal_kerja_kelompok_id= (int) $a_reals['sc_jadwal_kerja_kelompok_id'];	
			
		}	
	}	
	if($jadwal_kerja_kelompok_id <=0 OR  $jadwal_kerja_kelompok_id >=21){
	
		//cari di kekaryawan
		$karyawan = loaddata_karyawan( $karyawan_id );
		$waktu_kerja_id= (int) isset( $karyawan['waktu_kerja_id'] )? $karyawan['waktu_kerja_id'] : 0 ;  
		if($waktu_kerja_id>3){ //kelompoknya A,B.. harus dikonversi ke 1,2,3
			$kelompok=get_kalendar_shift_by_tanggal($tanggal, $karyawan['kelompok_shift_id'] );		
		}else{
			$kelompok=$karyawan['kelompok'] ;
		}	
		if( $kelompok=='X'){
			$jadwal_kerja_kelompok_id=21 ; //X
		}else{	
			$query = "SELECT * FROM a_jadwal_kerja_kelompok 
					WHERE waktu_kerja_id = {$waktu_kerja_id}
					AND kelompok='{$kelompok}' ";
			$res = my_query($query);
			$jadwals = my_fetch_array($res);
			$jadwal_kerja_kelompok_id=(int) $jadwals['jadwal_kerja_kelompok_id'];	
		}		
	}	
	return $jadwal_kerja_kelompok_id ;
}
/*
function get_periode_id_by_tanggal($tanggal){
	$tanggal=substr($tanggal,0,8).'01' ;
	$query = " SELECT  periode_id FROM pr_periode WHERE tanggal='".$tanggal."' LIMIT 1";
	$result = my_query($query);
	$data = my_fetch_array($result);
	return (int) $data['periode_id'];
}
*/

function get_periode_id_by_tanggal($tanggal){
	list($yyyy,$mm,$dd) = explode("-" , $tanggal);
	$yyyy=(int) $yyyy ;
	$mm=(int) $mm ;
	$dd= (int) $dd ;

	if( $dd>10 ){
		if($mm ==12 ){
			$mm = 1;
			$yyyy++ ;	
		}else{
			$mm++ ;
		}
	}
	$tanggal=$yyyy.'-'.sprintf( '%02d',$mm) .'-01';	
	$query = " SELECT  periode_id FROM pr_periode WHERE tanggal='".$tanggal."' LIMIT 1";
	$result = my_query($query);
	$data = my_fetch_array($result);
	return (int) $data['periode_id'];
}

function get_kalendar_shift_by_tanggal($tanggal , $kelompok_shift_id ){
	$periode_id=get_periode_id_by_tanggal($tanggal);
	list($yyyy,$mm,$dd) = explode("-" , $tanggal);
	$query = "SELECT tgl_{$dd} FROM a_kalendar_shift 
		WHERE periode_id = {$periode_id} 
		AND kelompok_shift_id={$kelompok_shift_id}";
	$result = my_query($query);
	$re = my_fetch_array($result);
	return $re['tgl_'.$dd];
}

function get_batas_tmt($periode_id = NULL){
	$periode_id =isset(	$periode_id)  ? 	$periode_id  : get_periode_gaji(); 	
	$periode = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$bulan = (int) date('m' , strtotime($periode['tanggal']));
	$tahun = $periode['tahun'] ;
	$end=$periode['tahun'].'-'. sprintf( '%02d',$bulan) .'-21' ;
	return $end ;
}	
/*
	INLOOP {
		$datas[] = array(
			'k1'=>array($text , 20 ,'STR_PAD_RIGHT|STR_PAD_BOTH|STR_PAD_LEFT'),//POSISI PILIH JUMLAH KARAKTER MAKSIMUM 20 POSISI
			'k2'=>array($text , 20 ,'STR_PAD_RIGHT|STR_PAD_BOTH|STR_PAD_LEFT'),
		);
	}
	
DEMO	
echo '<pre>';
$datas = array();
for($i = 1; $i<10; $i++){
	$datas[] = array(
		'k1'=>array( substr(md5( rand(0,110) ) ,0,rand(20,30)),35 ,STR_PAD_RIGHT),
		'k2'=>array(  rand(1000,1010)  ,5 ,STR_PAD_LEFT),
		'k3'=>array(  rand(100000,101000)  ,7 ,STR_PAD_RIGHT),
	);
}
echo set_txt_report($datas);
*/
function set_txt_report($datas){
	if(! is_array($datas )) return false;

	$v ='<script>window.print();</script>';
	foreach($datas as  $content){
		$wrap_text='' ;
		// Tambahan wordwrap asumsi 2 baris dulu
		foreach( $content as $k => $value){ 
			if(  strlen($value[0])>$value[1] ){
				$v.= str_pad( substr($value[0], 0, $value[1]) ,$value[1]," ",$value[2]).' ';
				$wrap_text.=str_pad( substr($value[0], $value[1], $value[1]),$value[1]," ",$value[2]).' ';
			}else{
				$wrap_text.=str_repeat ( ' ', $value[1]).' ';
				$v.= str_pad($value[0],$value[1]," ",$value[2]).' '; 
			}
		}		
		$v.="\n";
		if( trim($wrap_text)<>'' ){
			$v.=$wrap_text."\n";
		}
 	}  
	return $v;
} 

function get_kolom_konstanta($id){
	$query = "
		SELECT value FROM konfigurasi_konstanta
		WHERE kolom_id = {$id} ";
	$res = my_query($query);
	$rw = my_fetch_array($res); 
	return $rw['value'];
}

function get_form_hidden($temp_id,$value){
	if( isset($value) ){
		$temp = array('name'=>$temp_id,'value'=>$value,'id'=>$temp_id,'type'=>'hidden',);
		$form_temp = form_dynamic($temp);
		return $form_temp;
	}
	return '';
}		


//================================================
//		Proc buat Terbilang
//================================================
function fterbilang($nnumber){
	$nlen=strlen( trim( $nnumber ));
	$cnumber=str_repeat("0", 3- ( $nlen%3==0 ? 3 : $nlen%3) ).trim( $nnumber );
	$ndigit=strlen( $cnumber ) / 3 ;
	$cresult='' ;
	for ($ncount=0;  $ncount<=$nlen ; $ncount+=3){
		$temp= (int) substr( $cnumber , $ncount, 3) ;
		if( $ndigit==2 AND $temp==1 ){
			$cresult.="Seribu " ;
		}else{	
			$cresult.=fsay( $temp ) ;
			if( $temp <> 0 ){
				if( $ndigit==2 ){
					$cresult.="Ribu " ;
				}elseif( $ndigit==3 ){	
					$cresult.="Juta " ;
				}elseif( $ndigit==4 ){	
					$cresult.="Milyar " ;					
				}elseif( $ndigit==4 ){	
					$cresult.="Trilyun " ;	
				}	
			}		
		}
		$ndigit--;
	}
	return $cresult;
}	

function fsay($cnumber){
	$nlen=strlen($cnumber) ;
	$ctemp=substr($cnumber,-2) ; // check 2 digit terakhir
	if( $ctemp=="00" ){
		$cresult="" ;
	}elseif( (int) $ctemp < 12 ){
		$cresult=returnAngka( $ctemp ) ;
	}elseif( substr($ctemp,-1)=="0" ){
		$cresult=returnAngka( substr($ctemp,0,1) )."Puluh " ;
	}elseif( (int) $ctemp < 20 ){
		$cresult=returnAngka( $ctemp%10 )."Belas " ;	
	}else{
		$cresult=returnAngka( substr($ctemp,0,1) )."Puluh ".returnAngka( substr($ctemp,-1) ) ;
	}	
	if($nlen<3){
		return $cresult ;
	}
	$ctemp=substr($cnumber,-3,1) ; //check digit ke-3 dari akhir
	if( $ctemp=="0" ){
	}else{
		if( $ctemp=="1" ){
			$cresult="Seratus ".$cresult ;
		}else{	
			$cresult=returnAngka( $ctemp )."Ratus ".$cresult ;
		}
	}
	return $cresult ;
}

function returnAngka($num){
	$str;
	$angkas = array("", "Satu ", "Dua ", "Tiga ", "Empat ", "Lima ", "Enam ", "Tujuh ", "Delapan ", "Sembilan ", "Sepuluh ", "Sebelas ");
	$str = $angkas[floor($num)];
	return $str;
}	